package com.example.blog.model;

import com.example.blog.Common.Constants;
import lombok.Data;
//统一返回结果实体类
//a.code     状态码
//b.errMsg   错误信息
//c.data     业务返回数据

@Data
public class Result <T>{
    //200成功，-1失败
    private int code;
    private String errMsg;
    private T data;
    //当执行成功时候，统一返回的
    public static <T> Result<T> success(Object data){
     Result result=new Result();
     result.setCode(Constants.RESULT_CODE_SUCCESS);
     result.setErrMsg("");
     result.setData(data);
     return result;
    }
    public static <T>Result <T> fail(String errMsg){
        Result result=new Result();
        result.setCode(Constants.RESULT_CODE_FAIL);
        result.setErrMsg(errMsg);
        result.setData(" ");
         return  result;
    }
    public static <T>Result <T> fail(String errMsg,T data){
        Result result=new Result();
        result.setCode(Constants.RESULT_CODE_FAIL);
        result.setErrMsg(errMsg);
        result.setData(data);
        return  result;
    }











}
